home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 February / february_2000.iso / site building / GoLive 4.0 Tryout / data1.cab / Apps / Modules / JScripts / ActionScripts / State.scpt < prev   
Encoding:
Text File  |  1999-08-05  |  2.3 KB  |  93 lines

  1. CSStateArray = new Object;
  2. CSCookieArray = new Object;
  3. CSCookieValArray = new Object;
  4.  
  5. function CSWriteCookie(action) {
  6.     var name   = "DFT" + action[1];
  7.     var hrs    = action[2];
  8.     var path   = action[3];
  9.     var domain = action[4];
  10.     var secure = action[5];
  11.     
  12.     var exp    = new Date((new Date()).getTime() + hrs * 3600000);
  13.     
  14.     var cookieVal = "";
  15.     for(var prop in CSCookieArray) {
  16.         if(("DFT" + CSCookieArray[prop]) == name) {
  17.             if(cookieVal != "") cookieVal += "&";
  18.             cookieVal += prop + ":" + escape(CSStateArray[prop]);
  19.         }
  20.     }
  21.     if(hrs != 0)
  22.         cookieVal += "; expires=" + exp.toGMTString();
  23.     if(path != "")
  24.         cookieVal += "; path=" + path;
  25.     if(domain != "")
  26.         cookieVal += "; domain=" + domain;
  27.     if(secure == true)
  28.         cookieVal += "; secure";
  29.         
  30.     //alert(cookieVal);
  31.     document.cookie = name + '=' + cookieVal;
  32. }
  33.  
  34. function CSReadCookie(action) {
  35.     var name    = "DFT" + action[1];
  36.     var cookies = document.cookie;
  37.  
  38.     if(cookies == "") return;
  39.  
  40.     var start = cookies.indexOf(name);
  41.     if(start == -1) return;
  42.  
  43.     start += name.length + 1;
  44.     var end = cookies.indexOf(";", start);
  45.     if(end == -1) end = cookies.length;
  46.         
  47.     var cookieVal = cookies.substring(start, end);
  48.     
  49.     var arr = cookieVal.split('&');
  50.     for(var i = 0; i < arr.length; i++) {
  51.         var a = arr[i].split(':');
  52.         CSStateArray[a[0]] = unescape(a[1]);
  53.     }    
  54. }
  55.  
  56. function CSDefineState(action) {
  57.     CSCookieArray[action[1]] = action[3]; 
  58. }
  59.  
  60. function CSSetState(action) {
  61.     CSStateArray[action[1]] = action[2];
  62. }
  63.  
  64. function CSInitState(action) {
  65.     if(typeof(CSStateArray[action[1]]) == "undefined")
  66.         CSStateArray[action[1]] = action[2];
  67. }
  68.  
  69. function CSCheckState(action) {
  70.     var obj1 = CSStateArray[action[1]];
  71.     var obj2 = action[2];
  72.  
  73.     if(typeof(obj1) == "object") {
  74.         for(var i=0;i<obj1.length;i++) {
  75.             if(obj1[i] != obj2[i])
  76.                 return false;
  77.             }
  78.         return true;
  79.         }
  80.         
  81.     var res;
  82.     var op = action[3];
  83.              if(op == "==") res = (CSStateArray[action[1]] == action[2]);    
  84.         else if(op == "!=") res = (CSStateArray[action[1]] != action[2]);    
  85.         else if(op == ">" ) res = (CSStateArray[action[1]] >  action[2]);    
  86.         else if(op == ">=") res = (CSStateArray[action[1]] >= action[2]);    
  87.         else if(op == "<" ) res = (CSStateArray[action[1]] <  action[2]);    
  88.         else if(op == "<=") res = (CSStateArray[action[1]] <= action[2]);    
  89.  
  90.     return res;
  91. }
  92.  
  93.